package net.wxxr.utils;

import com.ykdl.member.kid.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

public class PopupWindowUtil {
	private static PopupWindowUtil instance = new PopupWindowUtil();

	private PopupWindowUtil() {
	}

	public static PopupWindowUtil getInstance() {
		if (instance == null) {
			instance = new PopupWindowUtil();
		}
		return instance;
	}

	private static AlertDialog dialog;
	private static ListView dialog_pick_number_lv;
	private static TextView dialog_pick_number_tv;
	static BaseAdapter myAdapter;
	PopupWindow window = null;

	public void showSelectStore(Activity activity, View anchor) {
		if (window != null && window.isShowing()) {
			return;
		}
		View view = View.inflate(activity, R.layout.windows_popupwindow, null);
		view.getBackground().setAlpha(70);
		window = new PopupWindow(view, LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT, true);
		window.setContentView(view);
		window.setFocusable(true);
		window.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
					window.dismiss();
					return true;
				}
				return false;
			}
		});
		window.setTouchable(true);
		window.setOutsideTouchable(true);
		window.setBackgroundDrawable(new ColorDrawable());
		window.showAsDropDown(anchor);
	}
}
